home *** CD-ROM | disk | FTP | other *** search
- /*
- File: OTLLCTest.c
-
- Contains: Simple app write or receive 8022 Ethernet packets using a multicast address
-
- Written by: Rich Kubota
-
- Copyright: © 1993-1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- This program implements both a sender and receiver such that both sides
- open an 802.2 Ethernet endpoint. The user can then select whether to run the
- program as a sender or receiver. If implemented as a receiver, the endpoint
- is bound, and the multicast option is turned on. The receiver waits in a
- spin loop for a specified period of time before quitting. The receiver will process
- all incoming ethernet packets destined to the endpoint for the specified
- protocol. Upon receipt, the program checks to see whether the packet was sequential
- to the previous packet. A collection of global counter maintains the number of
- inOrder, outOfOrder packets, and the number of packets reads resulting in an error,
- plus the number of packets which come in back to back while in the handler.
-
- Note the this sample turns on the rawmode option so that the handler will be passed the
- 14 byte 802.2 header.
- Also note that the sender may also implement the rawmode option so that it can also
- fill in the header bytes itself. If this is done, then the buffer needs to
- be enlarged to include these additional bytes. These additional bytes will not affect
- the maximum tsdu size since the tsdu size is the i-frame limit and does not include
- the header size.
-
- The sender process, sends 10005 x 1496 byte packets as fast as possible. The user
- can select to to turn on AckSends mode where the packet is handed to OT and not
- released until OT sends the information to the lower layer.
-
-
-
- */
-
- #include <stdio.h>
- #include <Types.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Events.h>
- #include <OpenTransport.h> // open transport files
- #include <OpenTptLinks.h>
- #include <Time.h>
- #include <Errors.h>
- #include "OTLLCTest.h"
-
- //-----------------------------------------------------------------------------------------
- // Globals
- //-----------------------------------------------------------------------------------------
-
- EndpointRef gEndpoint;
- OSStatus gstatus;
- UInt32 gFlags;
- UInt32 gPacketsRead;
- UInt32 gBackToBackPackets; // counter of number of times a packet is read in addition to the first pcket
- UInt32 gInOrder;
- UInt32 gOutOfOrder;
- UInt32 gCounter;
- UInt32 gNumDataEvents;
- UInt32 gReadErrors;
- UInt8 *gBuffer;
- UInt8 *gDummyBuffer;
- Address8022 gAddr;
- UInt8 gmcAddr[k48BitAddrLength] = {MCASTADDR0,MCASTADDR1,MCASTADDR2,MCASTADDR3,MCASTADDR4,MCASTADDR5};
- Boolean gDone;
- //-----------------------------------------------------------------------------------------
- // Prototypes
- //-----------------------------------------------------------------------------------------
- extern OSStatus DoNegotiateRawModeOption(EndpointRef ep, UInt32 rawModeOption);
- OSStatus DoBind();
- OSStatus DoAddMulticast(EndpointRef ep, unsigned char *mcAddr);
- OSStatus DoRemoveMulticast(EndpointRef ep, unsigned char *mcAddr);
- void WriteApplIntro(void);
- UInt32 GetYesNoOption(void);
- UInt32 GetUserOption(void);
- void DoOTLLCWriteTest(void);
- void DoOTLLCReadTest(void);
- OSStatus DoReadPacket(EndpointRef ep, UInt8 *mainBuffer);
- pascal void LLCEventHandler(void* ref, OTEventCode event, OTResult result, void* cookie);
- Boolean IsPressed(unsigned short k, unsigned char *keyMap);
- Boolean UserAbort(void);
- void DoValueBreak(long value, const char* message);
-
-
- /*******************************************************************************
- ** DoBindENET
- ********************************************************************************/
-
- OSStatus DoBind(void)
- {
- OSStatus osstatus;
- TBind requestInfo;
- TBind responseInfo;
- UInt32 i;
-
- gAddr.fAddrFamily = AF_8022;
-
- for (i = 0; i < k48BitAddrLength; i++)
- gAddr.fHWAddr[i] = 0x00;
-
- gAddr.fSAP = TESTSAP;
-
- // finish bind information
- requestInfo.addr.buf = (UInt8 *)&gAddr;
- requestInfo.addr.len = 10; // family type + Ethernet + type field
- requestInfo.addr.maxlen = 0;
- requestInfo.qlen = 0;
-
- responseInfo.addr.buf = (UInt8 *)&gAddr;
- responseInfo.addr.len = 0;
- responseInfo.addr.maxlen = 10; // family type + Ethernet + type field
- responseInfo.qlen = 0;
-
-
- SetStillBindFlag(gFlags);
-
- if (osstatus = OTBind(gEndpoint, &requestInfo, &responseInfo))
- {
- printf("\nCould not bind an endpoint, error = %d\n", osstatus);
- ClrStillBindFlag(gFlags);
- }
- else
- {
- while (TstStillBindFlag(gFlags))
- OTIdle();
- if (gstatus != kOTNoError)
- {
- printf("\nCould not bind an endpoint, error = %d\n", gstatus);
- osstatus = gstatus;
- }
- SetEPBoundFlag(gFlags);
- }
- return osstatus;
- }
-
-
-
- /*******************************************************************************
- ** DoAddMulticast
- ********************************************************************************/
-
- OSStatus DoAddMulticast(EndpointRef ep, unsigned char *mcAddr)
- {
- OSStatus osstatus = noErr;
- TOptMgmt ret;
- TOptMgmt req;
- UInt8 reqOpt[64];
- UInt8 retOpt[64];
-
- req.opt.buf = reqOpt;
- req.flags = T_NEGOTIATE;
-
- ret.opt.buf = retOpt;
- ret.opt.maxlen = sizeof(retOpt);
-
- ((TOption*)reqOpt)->level = LNK_TPI;
- ((TOption*)reqOpt)->name = OPT_ADDMCAST;
- ((TOption*)reqOpt)->len = kOTOptionHeaderSize + k48BitAddrLength;
- memcpy(((TOption*)reqOpt)->value, mcAddr, k48BitAddrLength);
-
- req.opt.len = kOTOptionHeaderSize + k48BitAddrLength;
-
- if ( (osstatus = OTOptionManagement(ep, &req, &ret)) != kOTNoError )
- fprintf(stderr, "DoAddMulticast - OptionManagement Returned %d\n", osstatus);
- else
- {
- fprintf(stderr, "DoAddMulticast - Option Status = %d\n", ((TOption*)retOpt)->status);
- SetMCastActiveFlag(gFlags);
- }
- return osstatus;
- }
-
-
- /*******************************************************************************
- ** DoRemoveMulticast
- ********************************************************************************/
-
- OSStatus DoRemoveMulticast(EndpointRef ep, unsigned char *mcAddr)
- {
- OSStatus osstatus = noErr;
- TOptMgmt ret;
- TOptMgmt req;
- UInt8 reqOpt[64];
- UInt8 retOpt[64];
-
- req.opt.buf = reqOpt;
- req.flags = T_NEGOTIATE;
-
- ret.opt.buf = retOpt;
- ret.opt.maxlen = sizeof(retOpt);
-
- ((TOption*)reqOpt)->level = LNK_TPI;
- ((TOption*)reqOpt)->name = OPT_DELMCAST;
- ((TOption*)reqOpt)->len = kOTOptionHeaderSize + k48BitAddrLength;
- memcpy(((TOption*)reqOpt)->value, mcAddr, k48BitAddrLength);
-
- req.opt.len = kOTOptionHeaderSize + k48BitAddrLength;
-
- if ( (osstatus = OTOptionManagement(ep, &req, &ret)) != kOTNoError )
- fprintf(stderr, "\nDoRemoveMulticast - OptionManagement Returned %d.", osstatus);
- else
- fprintf(stderr, "\nDoRemoveMulticast - Option Status = %d.", ((TOption*)retOpt)->status);
- return osstatus;
- }
-
- void WriteApplIntro(void)
- {
- fprintf(stderr, "\nEthernet 802.2 LLC Test program v1.0\n");
- fprintf(stderr, "\nThis test application sets the system");
- fprintf(stderr, "\ninto send or receive mode.\n");
- fprintf(stderr, "\nThe send portion of this program sets the Ethernet");
- fprintf(stderr, "\ndriver to use a multicast address, then sends 10000");
- fprintf(stderr, "\n- 1500 byte packets out the wire.\n");
- fprintf(stderr, "\nThe receive portion of this program sets the Ethernet");
- fprintf(stderr, "\ndriver to use a multicast address, then waits for the");
- fprintf(stderr, "\n10000 - 1500 byte packets or times out after 30 seconds.\n");
- }
-
- UInt32 GetYesNoOption(void)
- {
- UInt32 result;
- char selection[32];
- Boolean done;
-
- fprintf(stdout, "\n Enter Y - To accept option");
- fprintf(stdout, "\n Enter N - To decline option");
- fprintf(stdout, "\n Enter Q - To quit");
- fprintf(stdout, "\nYour selection -> ");
- fflush(stdout);
- done = false;
-
- do
- {
- scanf("%s", selection);
- switch (selection[0])
- {
- case 'y':
- case 'Y':
- result = kAcceptOption;
- done = true;
- break;
-
- case 'n':
- case 'N':
- result = kDeclineOption;
- done = true;
- break;
-
- case 'q':
- case 'Q':
- result = kQuitTest;
- done = true;
- break;
-
- default:
- fprintf(stdout, "\nInvalid entry - %c, try again -> ", selection);
- fflush(stdout);
- break;
-
- }
- } while (!done);
-
- fflush (stdout);
- return result;
- }
-
-
- UInt32 GetUserOption(void)
- {
- UInt32 result;
- char selection[32];
- Boolean done;
-
- fprintf(stdout, "\nSelect the type of test to run");
- fprintf(stdout, "\nMake sure that the receive program is already launched");
- fprintf(stdout, "\n Enter S - Send test packets");
- fprintf(stdout, "\n Enter R - Receive test packets");
- fprintf(stdout, "\n Enter q - quit");
- fprintf(stdout, "\nYour selection -> ");
- fflush(stdout);
- done = false;
-
- do
- {
- scanf("%s", selection);
- switch (selection[0])
- {
- case 'r':
- case 'R':
- result = kReceiveTest;
- done = true;
- break;
-
- case 's':
- case 'S':
- result = kSendTest;
- done = true;
- break;
-
- case 'q':
- case 'Q':
- result = kQuitTest;
- done = true;
- break;
-
- default:
- fprintf(stdout, "\nInvalid entry - %c, try again -> ", selection);
- fflush(stdout);
- break;
-
- }
- } while (!done);
-
- fflush (stdout);
- return result;
- }
-
- void DoOTLLCWriteTest(void)
- {
- OSStatus osstatus;
- TUnitData unitdata;
- UInt32 i;
- time_t t1, t2, t3;
- Address8022 dAddr;
- UInt16 rawModeOffset = 0;
- UInt8 data[DATASIZE+14]; // set data to be DATASIZE + space for rawmode header
-
-
- osstatus = DoBind();
-
- if (TstUseAckSendsFlag(gFlags))
- osstatus = OTAckSends(gEndpoint);
-
- if (TstUseRawModeFlag(gFlags))
- {
- osstatus = DoNegotiateRawModeOption(gEndpoint, kOTRawRcvOn);
- if (osstatus == kOTNoError)
- {
- SetRawModeFlag(gFlags);
- // if rawmode is on then we want to offset the data
- // an additional 17 bytes and set the header info
- // ourselves.
- // note that 17 bytes constitutes the 6 byte dAddr, 6 byte sAddr
- // 2 byte length field, 1 byte ssap, 1 byte dsap and 1 byte control byte
-
-
- rawModeOffset = 17;
- }
- else
- {
- // if the option failed, then we don't use it'
- fprintf (stdout, "\nError negotiating raw mode option");
- // reset the status result.
- osstatus = kOTNoError;
- }
- }
-
- if (osstatus == kOTNoError)
- {
- // set up the first 12 bytes past the control byte, so that we can recognize them
- data[0 + rawModeOffset] = 1;
- data[1 + rawModeOffset] = 2;
- data[2 + rawModeOffset] = 3;
- data[3 + rawModeOffset] = 4;
- data[4 + rawModeOffset] = 5;
- data[5 + rawModeOffset] = 6;
- data[6 + rawModeOffset] = 7;
- data[7 + rawModeOffset] = 8;
- data[8 + rawModeOffset] = 9;
- data[9 + rawModeOffset] = 10;
- data[10 + rawModeOffset] = 11;
- data[11 + rawModeOffset] = 12;
-
- // set up some specific bytes in the data buffer
- data[DATAOFFSET+0 + rawModeOffset] = 0;
- data[DATAOFFSET+1 + rawModeOffset] = 0;
- data[DATAOFFSET+2 + rawModeOffset] = 'L';
- data[DATAOFFSET+3 + rawModeOffset] = 'A';
- data[DATAOFFSET+4 + rawModeOffset] = 'S';
- data[DATAOFFSET+5 + rawModeOffset] = 'T';
- data[DATAOFFSET+6 + rawModeOffset] = 1;
- data[DATAOFFSET+7 + rawModeOffset] = 2;
- data[DATAOFFSET+8 + rawModeOffset] = 3;
- data[DATAOFFSET+9 + rawModeOffset] = 4;
- data[DATAOFFSET+10 + rawModeOffset] = 5;
- data[DATAOFFSET+11 + rawModeOffset] = 6;
-
-
- unitdata.udata.buf = (UInt8*)data;
-
- if (TstRawModeFlag(gFlags))
- unitdata.udata.len = DATASIZE + 14;
- else
- unitdata.udata.len = DATASIZE;
- unitdata.opt.len = 0;
- unitdata.opt.buf = NULL;
-
- if (TstUseRawModeFlag(gFlags) == false)
- {
- // set up the destination addresss
- dAddr.fAddrFamily = AF_8022;
-
- dAddr.fHWAddr[0] = MCASTADDR0;
- dAddr.fHWAddr[1] = MCASTADDR1;
- dAddr.fHWAddr[2] = MCASTADDR2;
- dAddr.fHWAddr[3] = MCASTADDR3;
- dAddr.fHWAddr[4] = MCASTADDR4;
- dAddr.fHWAddr[5] = MCASTADDR5;
-
- dAddr.fSAP = TESTSAP;
-
- unitdata.addr.buf = (UInt8*)&dAddr;
- unitdata.addr.len = 10; // size of the dAddr to include address type, address and sap
- }
- else
- {
- // set up for a rawmode send data call
- data[0] = MCASTADDR0;
- data[1] = MCASTADDR1;
- data[2] = MCASTADDR2;
- data[3] = MCASTADDR3;
- data[4] = MCASTADDR4;
- data[5] = MCASTADDR5;
- // set the packet len field
- data[12] = DATASIZE >> 8;
- data[13] = DATASIZE & 0xFF;
- // set the dsap, ssap, and control byte fields.
- data[14] = TESTSAP; // set DSAP
- data[15] = TESTSAP; // set SSAP
- data[16] = 0x03; // set control byte
-
- unitdata.addr.buf = nil; // don't want to set the destination address since we've already
- // done so in the data
- unitdata.addr.len = 0; // no addr field data to send
-
- }
-
-
- fprintf (stdout, "\n starting write of %ld llc packets of %ld bytes\n", (long)SENDCOUNT, (long)DATASIZE);
- fflush(stdout);
- t1 = clock ();
-
- gDone = false;
- i = 0;
- while (!gDone)
- {
- SetStillSendFlag(gFlags); // set flag to indicate we have not completed writing our packet
- ClrFlowClrFlag(gFlags); // clear the flag that indicates that a T_GODATA event occurred
- // we do this because a race condition might occur when we make the
- // the OTSndUData call, a flowerr may occur, but get cleared by the time
- // we actually check the osstatus field
- osstatus = OTSndUData(gEndpoint, &unitdata);
-
- switch (osstatus)
- {
- case kENOMEMErr:
- fprintf(stderr, "\nkENOMEMErr %d.", i);
- gDone = UserAbort();
- OTIdle(); // ran out of memory so idle
- break;
-
- case kOTNoError: // send was successful
- if (TstUseAckSendsFlag(gFlags))
- {
- while (TstAckSendsFlag(gFlags)) // if ack sends on, then wait until the T_MEMORYRELEASED event occurs
- gDone = UserAbort(); // which will clear the AckSendsFlag bit.
- }
-
- i++;
- if (i >= SENDCOUNT)
- gDone = true;
- else
- {
- data[DATAOFFSET+0+rawModeOffset] = i >> 8;
- data[DATAOFFSET+1+rawModeOffset] = i;
-
- // for test purposes, set the very last 2 bytes of the packet with count
-
- data[DATASIZE-2+rawModeOffset] = i >> 8;
- data[DATASIZE-1+rawModeOffset] = i;
- // go back around and send another packet
- }
- break;
-
- case kOTFlowErr:
- if (!TstFlowClrFlag(gFlags))
- {
- SetFlowErrFlag(gFlags); // a T_GODATA did not just come in
- fprintf(stderr, "\nflow error occurred while sending packet %d.", i);
- while (TstFlowErrFlag(gFlags) && !gDone)
- {
- gDone = UserAbort();
- }
-
- }
- else // a T_GODATA event snuck in on us
- ClrFlowErrFlag(gFlags);
- break;
-
- default:
- gDone = true;
- fprintf(stderr, "\nOTSndUData error returned %d\n", osstatus);
- fprintf(stderr, "\nwhile sending packet %d.", i);
- ClrStillSendFlag(gFlags);
- break;
- }
-
-
- } // end while loop sending data
-
- t2 = clock();
- t3 = t2 - t1;
- fprintf (stdout, "\nCompleted sending %ld llc packets.", (long)SENDCOUNT);
- fprintf (stdout, "\nTime start = %ld, time end = %ld, time taken %ld seconds.",
- t1, t2, (long)t3/CLOCKS_PER_SEC);
- fprintf (stdout, "\nPackets per second = %ld, bytes/second = %ld.",
- ((long)SENDCOUNT*CLOCKS_PER_SEC)/t3, ((long)SENDCOUNT*DATASIZE*CLOCKS_PER_SEC)/t3);
-
- fflush(stdout);
-
-
- } // end if bind successful
-
- if (TstEPBoundFlag(gFlags))
- {
- OTSetSynchronous(gEndpoint);
- OTUnbind(gEndpoint);
- }
- }
-
- void DoOTLLCReadTest(void)
- {
- OSStatus osstatus;
- long timer;
-
- gBuffer = (UInt8*)NewPtr(DATASIZE + 2* DATASLOP); // allocate the data buffer + some slop
- if (gBuffer)
- osstatus = DoBind();
- else
- {
- osstatus = memFullErr;
- return;
- }
-
- gBackToBackPackets = 0;
- gInOrder = 0;
- gOutOfOrder = 0;
- gCounter = 0;
- gPacketsRead = 0;
- gNumDataEvents = 0;
- gReadErrors = 0;
- gDone = false;
-
- if (osstatus == kOTNoError)
- {
- SetWaitOptMgmtFlag(gFlags);
- osstatus = DoAddMulticast(gEndpoint, gmcAddr);
- while(TstWaitOptMgmtFlag(gFlags));
- }
-
- if (osstatus == kOTNoError)
- {
- if (TstUseRawModeFlag(gFlags))
- {
- osstatus = DoNegotiateRawModeOption(gEndpoint, kOTRawRcvOn);
- if (osstatus == kOTNoError)
- {
- SetRawModeFlag(gFlags);
- }
- else
- {
- // if the option failed, then we don't use it'
- fprintf (stdout, "\nError negotiating raw mode option");
- // reset the status result.
- osstatus = kOTNoError;
- }
- }
- }
-
- if (osstatus == kOTNoError)
- {
- SetWantDataFlag(gFlags);
-
- fprintf (stdout, "\nStarting Read test - will terminate in %d seconds", TIMEOUT);
- fprintf (stdout, "\nor as soon as the trigger packet is received.");
- fprintf (stdout, "\nYou may also use Command . to end this test");
- fprintf (stdout, "\nStarting Read");
- fflush(stdout);
-
- timer = TickCount() + TIMEOUT * 60;
- // loop until timer is less than TickCount or until the endtime value gets set
-
- while ((timer > TickCount()) && (gDone == false))
- {
- // allow the user to exit the timer loop by
- gDone = UserAbort();
- }
-
-
-
- }
-
- OTSetSynchronous(gEndpoint);
-
- if (TstMCastActiveFlag(gFlags))
- DoRemoveMulticast(gEndpoint, gmcAddr);
-
-
- if (osstatus == kOTNoError)
- {
- fprintf (stdout, "\n\nBufferReadCount = %ld", gPacketsRead);
- fprintf (stdout, "\nInOrder = %ld\n", gInOrder);
- fprintf (stdout, "\nOutofOrder = %ld\n", gOutOfOrder);
- fprintf (stdout, "\nlast packet read was = %ld\n", gCounter);
- fprintf (stdout, "\nNumber of data events was = %ld\n", gNumDataEvents);
- fprintf (stdout, "\nNumber of read errors was = %ld\n", gReadErrors);
- fprintf (stdout, "\nNumber of back to back packets was = %ld\n", gBackToBackPackets);
- fflush(stdout);
- }
-
- if (TstEPBoundFlag(gFlags))
- OTUnbind(gEndpoint);
-
- if (gBuffer)
- DisposePtr((Ptr)gBuffer);
-
- }
-
- OSStatus DoReadPacket(EndpointRef ep, UInt8 *mainBuffer)
- {
- TUnitData unitdata;
- Address8022 dAddr;
- OTFlags otFlags;
- OSStatus result, tempResult;
-
- unitdata.addr.maxlen = 10;
- unitdata.addr.buf = (UInt8*)&dAddr;
- unitdata.udata.buf = mainBuffer;
- unitdata.udata.maxlen = DATASIZE + DATASLOP;
- unitdata.opt.maxlen = 0;
-
- result = OTRcvUData(ep, &unitdata, &otFlags);
- return result;
- }
-
- pascal void LLCEventHandler(void* ref, OTEventCode event, OTResult result, void* cookie)
- {
- OSStatus osstatus;
- UInt8 *bufferToUse;
- UInt32 lcounter, offset;
- Boolean firstTimeFlag;
-
- gstatus = result;
- switch (event)
- {
- case T_MEMORYRELEASED:
- ClrAckSendsFlag(gFlags);
- break;
-
- case T_OPTMGMTCOMPLETE:
- ClrWaitOptMgmtFlag(gFlags);
- break;
-
- case T_BINDCOMPLETE:
- ClrStillBindFlag(gFlags);
- break;
-
- case T_UNBINDCOMPLETE:
- break;
-
- case T_GODATA:
- DebugStr("\pFlow Control occurred;g");
- SetFlowClrFlag(gFlags); // indicate that the flow data problem has now cleared.
- break;
-
- case T_DATA:
- gNumDataEvents++;
- if (TstWantDataFlag(gFlags))
- bufferToUse = gBuffer;
- else
- bufferToUse = gDummyBuffer;
-
- // initialize variables as we enter while loop
- osstatus = kOTNoError;
- firstTimeFlag = true;
-
- while ((osstatus == kOTNoError) && (!gDone))
- {
- osstatus = DoReadPacket(gEndpoint, bufferToUse);
-
- if (firstTimeFlag == true)
- // this is the first time through this loop
- // for this call to the handler
- firstTimeFlag = false;
- else
- // increment the counter to indicate that there was a packet to
- // handle after reading the previous packet
- gBackToBackPackets++;
-
- if (osstatus != kOTNoDataErr)
- {
- if (osstatus < 0)
- gReadErrors++;
- else
- gPacketsRead++;
- }
-
- if (TstWantDataFlag(gFlags) && (osstatus == kOTNoError))
- {
- if (TstRawModeFlag(gFlags))
- // if rawmode is on then we want to account for
- // the additional 17 bytes which will be at the
- // beginning of the packet.
- offset = 17;
- else
- offset = 0;
-
- lcounter = gBuffer[DATAOFFSET + offset +0] << 8;
- lcounter |= gBuffer[DATAOFFSET + offset +1];
- if (lcounter >= TRIGGEREND)
- {
- gDone = true; // we can bail now.
- }
- else
- {
- if (lcounter == gCounter)
- gInOrder++;
- else
- gOutOfOrder++;
-
- gCounter = lcounter + 1; // prepare gCounter for next incoming packet to compare
- }
- }
- }
- break;
-
- default:
- DoValueBreak(event, "Unknown event occurred # ;g");
- break;
-
-
- } /* end switch on event */
- }
-
- /*******************************************************************************
- ** IsPressed
- ********************************************************************************/
-
- Boolean IsPressed(unsigned short k, unsigned char *keyMap)
- {
- return (keyMap[k >> 3] >> (k & 7) & 1);
- }
-
- /*******************************************************************************
- ** CmdKey
- ********************************************************************************/
-
- Boolean UserAbort()
- {
- unsigned char keyMap[16];
- EventRecord event;
- Boolean result;
-
- GetKeys((unsigned long*)keyMap);
- // GetKeys(( long*)keyMap);
- if ( IsPressed(0x37, keyMap) && // is command period or esc key hit
- (IsPressed(0x2F, keyMap) || IsPressed(0x41, keyMap)) )
- result = true;
- else
- result = false;
-
- return result;
- }
-
- main (void)
- {
- OSStatus osstatus = noErr;
- UInt32 selection;
-
- WriteApplIntro();
- gFlags = 0;
- if (osstatus = InitOpenTransport())
- {
- fprintf(stderr, "\n\nOpen Transport is not installed!\n");
- fprintf(stderr, "\nBye Bye.\n");
- }
- else
- {
- SetOTActiveFlag(gFlags); // indicate that OT is active
-
- gDummyBuffer = (UInt8*)NewPtr(DATASIZE + 2 * DATASLOP);
- if (gDummyBuffer == NULL)
- osstatus = memFullErr;
- }
-
- if (osstatus == kOTNoError)
- {
- // open the default ethernet endpoint
- gEndpoint = OTOpenEndpoint(OTCreateConfiguration(kEnetName), (OTOpenFlags)NULL, NULL, &osstatus);
- if (osstatus != kOTNoError)
- {
- fprintf(stderr, "\n\nError opening Ethernet endpoint!");
- fprintf(stderr, "\nOTOpenEndpoint returned %d\n", osstatus);
- fprintf(stderr, "\nBye Bye.\n");
- }
- else
- SetEPActiveFlag(gFlags); // indicate that the endpoint is opened
- }
-
- if (osstatus == kOTNoError)
- {
- osstatus = OTInstallNotifier(gEndpoint, LLCEventHandler, NULL);
- if (osstatus != kOTNoError)
- {
- fprintf(stderr, "\n\nError installing notifier!");
- fprintf(stderr, "\nOTInstallNotifier returned %d\n", osstatus);
- }
- } // now ready to handle async events
-
- if (osstatus == kOTNoError)
- {
- osstatus = OTSetAsynchronous(gEndpoint);
- if (osstatus != kOTNoError)
- {
- fprintf(stderr, "\n\nError making endpoint asynchronous!");
- fprintf(stderr, "\nOTSetAsynchronous returned %d\n", osstatus);
- }
- } // now ready to handle async events
-
- if (osstatus == kOTNoError)
- {
- // ask whether to use the rawmode option or not
- fprintf(stdout, "\nDo you want to use the raw mode option?");
- selection = GetYesNoOption();
- if (selection == kQuitTest)
- {
- fprintf(stderr, "\n\nBye-Bye!");
- osstatus = -1;
- }
- else if (selection == kAcceptOption)
- SetUseRawModeFlag(gFlags);
- }
-
- if (osstatus == kOTNoError)
- {
-
- // what does the user want to do
- selection = GetUserOption();
-
- switch (selection)
- {
- case kSendTest:
- fprintf(stdout, "\nDo you want to turn on AckSends?");
- selection = GetYesNoOption();
- if (selection == kQuitTest)
- {
- fprintf(stderr, "\n\nBye-Bye!");
- break;
- }
- else if (selection == kAcceptOption)
- SetUseAckSendsFlag(gFlags);
-
- DoOTLLCWriteTest();
- break;
-
- case kReceiveTest:
- DoOTLLCReadTest();
- break;
-
- case kQuitTest:
- default:
- fprintf(stderr, "\n\nBye-Bye!");
- break;
- }
- }
-
- // force endpoint to be synchronous
- OTSetSynchronous(gEndpoint);
-
- if (TstEPActiveFlag(gFlags))
- OTCloseProvider(gEndpoint);
-
- if (gDummyBuffer)
- DisposePtr((Ptr)gDummyBuffer);
-
- if (TstOTActiveFlag(gFlags))
- CloseOpenTransport();
-
- fprintf(stderr, "\nProgram ended");
- }
-
- void DoValueBreak(long value, const char* message)
- {
- static short sDoErrorBreak = 0;
-
- {
- Str255 s,
- n = "\p";
-
- s[0] = strlen(message);
- BlockMoveData(message,&s[1],s[0]);
- if (value < 0)
- {
- s[0] += 1;
- s[s[0]] = '-';
- value = -value;
- }
- while (value)
- {
- if (n[0])
- BlockMoveData(&n[1],&n[2],n[0]);
- n[0]++;
- n[1] = 48 + (value % 10);
- value /= 10;
- }
- BlockMoveData(&n[1],&s[s[0]+1],n[0]);
- s[0] += n[0];
-
- sDoErrorBreak++;
- {
- short cnt = sDoErrorBreak;
-
- s[0]++;
- s[s[0]] = ',';
- s[0]++;
- s[s[0]] = ' ';
- n[0] = 0;
- while (cnt)
- {
- if (n[0])
- BlockMoveData(&n[1],&n[2],n[0]);
- n[0]++;
- n[1] = 48 + (cnt % 10);
- cnt /= 10;
- }
- BlockMoveData(&n[1],&s[s[0]+1],n[0]);
- s[0] += n[0];
- }
- DebugStr(s);
- }
- }
-